package processor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;

public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
//        System.out.println("BeanDefinitionMap填充完毕后执行该方法");
//        BeanDefinition beanDefinition=configurableListableBeanFactory.getBeanDefinition("userService");
//        beanDefinition.setBeanClassName("dao.impl.UserDaoImpl");
        //动态注入
        BeanDefinition beanDefinition=new RootBeanDefinition();
        beanDefinition.setBeanClassName("dao.impl.presonDaoImp");

        DefaultListableBeanFactory defaultListableBeanFactory=(DefaultListableBeanFactory) configurableListableBeanFactory;
        defaultListableBeanFactory.registerBeanDefinition("presonDao",beanDefinition);

    }
}
